﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Configuration;
using log4net;

namespace CONEXAO
{
    public class ConexaoBanco
    {
        #region "Declaração de variáveis"
        private static log4net.ILog log;
        #endregion

        public static SqlConnection GetConexao()
        {
            log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            log4net.Config.XmlConfigurator.Configure();

            var strConexao = ConfigurationManager.ConnectionStrings["BD_Mensageiros"].ConnectionString;
            var conn = new SqlConnection(strConexao);

            try
            {
                conn.Open();
                return conn;
            }
            catch (SqlException ex)
            {
                log.Error(ex);
                throw new Exception("Falha de Conexão com o Banco de Dados." + ex.Message);
            }
            finally
            {
                conn.Close();
            }
        }
    }
}
